/*
 * ============================================================================
 *                   GNU Lesser General Public License
 * ============================================================================
 *
 *
 *
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 * 
 *
 *
 */
package rad.framework.log;

import java.text.MessageFormat;

import org.apache.commons.logging.Log;

/**
 * This class cleans up logging by checking if the level is enabled and then
 * formating the text.
 * 
 * @author boudyacho
 * 
 */
public class Logger {

	// TODO exceptions
	// TODO Message Source

	private static String format(String text, Object... value) {
		MessageFormat format = new MessageFormat(text);
		return format.format(value);
	}

	public static void trace(Log log, String text, Object... value) {
		if (log.isTraceEnabled()) {
			log.trace(format(text, value));
		}
	}

	public static void debug(Log log, String text, Object... value) {
		if (log.isDebugEnabled()) {
			log.debug(format(text, value));
		}
	}

	public static void info(Log log, String text, Object... value) {
		if (log.isInfoEnabled()) {
			log.info(format(text, value));
		}
	}

	public static void warn(Log log, String text, Object... value) {
		if (log.isWarnEnabled()) {
			log.warn(format(text, value));
		}
	}

	public static void error(Log log, String text, Object... value) {
		if (log.isErrorEnabled()) {
			log.error(format(text, value));
		}
	}

	public static void fatal(Log log, String text, Object... value) {
		if (log.isFatalEnabled()) {
			log.fatal(format(text, value));
		}
	}

	public static void stackTrace(Log log, String text, Object... value) {
		Exception e = new Exception();
		if (log.isDebugEnabled()) {
			log.debug(format(text, value), e);
		}
	}
}
